import { LocalLanguage } from "./types";
import { getObjectArrayMapEntries } from "./util";

const supportedLanguagesLongCode: LocalLanguage[] = [
    { longCode: "af"      , shortCode: "AF",  label: "Afrikaans" },
    { longCode: "af-za"   , shortCode: "AFK", label: "Afrikaans - South Africa", },
    { longCode: "sq-al"   , shortCode: "SQI", label: "Albanian - Albania", },
    { longCode: "ar"      , shortCode: "AR" , label: "Arabic" },
    { longCode: "ar-dz"   , shortCode: "ARG", label: "Arabic - Algeria", },
    { longCode: "ar-bh"   , shortCode: "ARH", label: "Arabic - Bahrain", },
    { longCode: "ar-eg"   , shortCode: "ARE", label: "Arabic - Egypt", },
    { longCode: "ar-iq"   , shortCode: "ARI", label: "Arabic - Iraq", },
    { longCode: "ar-jo"   , shortCode: "ARJ", label: "Arabic - Jordan", },
    { longCode: "ar-kw"   , shortCode: "ARK", label: "Arabic - Kuwait", },
    { longCode: "ar-lb"   , shortCode: "ARB", label: "Arabic - Lebanon", },
    { longCode: "ar-ly"   , shortCode: "ARL", label: "Arabic - Libya", },
    { longCode: "ar-ma"   , shortCode: "ARM", label: "Arabic - Morocco", },
    { longCode: "ar-om"   , shortCode: "ARO", label: "Arabic - Oman", },
    { longCode: "ar-qa"   , shortCode: "ARQ", label: "Arabic - Qatar", },
    { longCode: "ar-sa"   , shortCode: "ARA", label: "Arabic - Saudi Arabia", },
    { longCode: "ar-sy"   , shortCode: "ARS", label: "Arabic - Syria", },
    { longCode: "ar-tn"   , shortCode: "ART", label: "Arabic - Tunisia", },
    { longCode: "ar-ae"   , shortCode: "ARU", label: "Arabic - United Arab Emirates", },
    { longCode: "ar-ye"   , shortCode: "ARY", label: "Arabic - Yemen", },
    { longCode: "az"      , shortCode: "AZ" , label: "Azeri (Latin)" },
    { longCode: "hy-am"   , shortCode: "HYE", label: "Armenian - Armenia", },
    { longCode: "eu"      , shortCode: "EU" , label: "Basque" },
    { longCode: "eu-es"   , shortCode: "EUQ", label: "Basque - Basque", },
    { longCode: "be"      , shortCode: "BE" , label: "Belarusian" },
    { longCode: "be-by"   , shortCode: "BEL", label: "Belarusian - Belarus", },
    { longCode: "bg"      , shortCode: "BG" , label: "Belarusian" },
    { longCode: "bg-bg"   , shortCode: "BGR", label: "Bulgarian - Bulgaria", },
    { longCode: "ca"      , shortCode: "CA" , label: "Catalan" },
    { longCode: "ca-es"   , shortCode: "CAT", label: "Catalan - Catalan", },
    { longCode: "zh-cn"   , shortCode: "CHS", label: "Chinese - China", },
    { longCode: "zh-hk"   , shortCode: "ZHH", label: "Chinese - Hong Kong SAR", },
    { longCode: "zh-mo"   , shortCode: "ZHM", label: "Chinese - Macau SAR", },
    { longCode: "zh-sg"   , shortCode: "ZHI", label: "Chinese - Singapore", },
    { longCode: "zh-tw"   , shortCode: "CHT", label: "Chinese - Taiwan", },
    { longCode: "zh-chs"  , shortCode: "CHS", label: "Chinese (Simplified)", },
    { longCode: "zh-cht"  , shortCode: "CHT", label: "Chinese (Traditional)", },
    { longCode: "hr-hr"   , shortCode: "HRV", label: "Croatian - Croatia", },
    { longCode: "cs"      , shortCode: "CS" , label: "Czech" },
    { longCode: "cs-cz"   , shortCode: "CSY", label: "Czech - Czech Republic", },
    { longCode: "da"      , shortCode: "DA" , label: "Danish" },
    { longCode: "da-dk"   , shortCode: "DAN", label: "Danish - Denmark", },
    { longCode: "nl-be"   , shortCode: "NLB", label: "Dutch - Belgium", },
    { longCode: "nl-nl"   , shortCode: "NLD", label: "Dutch - The Netherlands", },
    { longCode: "en"      , shortCode: "EN" , label: "English" },
    { longCode: "en-au"   , shortCode: "ENA", label: "English - Australia", },
    { longCode: "en-bz"   , shortCode: "ENL", label: "English - Belize", },
    { longCode: "en-ca"   , shortCode: "ENC", label: "English - Canada", },
    { longCode: "en-cb"   , shortCode: "ENB", label: "English - Caribbean", },
    { longCode: "en-ie"   , shortCode: "ENI", label: "English - Ireland", },
    { longCode: "en-jm"   , shortCode: "ENJ", label: "English - Jamaica", },
    { longCode: "en-nz"   , shortCode: "ENZ", label: "English - New Zealand", },
    { longCode: "en-ph"   , shortCode: "ENG", label: "English - Philippines", },
    { longCode: "en-za"   , shortCode: "ENS", label: "English - South Africa", },
    { longCode: "en-tt"   , shortCode: "ENG", label: "English - Trinidad and Tobago", },
    { longCode: "en-gb"   , shortCode: "ENG", label: "English - United Kingdom", },
    { longCode: "en-us"   , shortCode: "ENU", label: "English - United States", },
    { longCode: "en-zw"   , shortCode: "ENW", label: "English - Zimbabwe", },
    { longCode: "eo"      , shortCode: "EO" , label: "Esperanto" },
    { longCode: "et"      , shortCode: "ET" , label: "Estonian" },
    { longCode: "et-ee"   , shortCode: "ETI", label: "Estonian - Estonia", },
    { longCode: "fo"      , shortCode: "FO" , label: "Faroese" },
    { longCode: "fo-fe"   , shortCode: "FOS", label: "Faroese - Faroe Islands", },
    { longCode: "fa"      , shortCode: "FA" , label: "Farsi" },
    { longCode: "fa-ir"   , shortCode: "FAR", label: "Farsi - Iran", },
    { longCode: "fi"      , shortCode: "FI" , label: "Finnish" },
    { longCode: "fi-fi"   , shortCode: "FIN", label: "Finnish - Finland", },
    { longCode: "fr"      , shortCode: "FR" , label: "French" },
    { longCode: "fr-be"   , shortCode: "FRB", label: "French - Belgium", },
    { longCode: "fr-ca"   , shortCode: "FRC", label: "French - Canada", },
    { longCode: "fr-fr"   , shortCode: "FRA", label: "French - France", },
    { longCode: "fr-lu"   , shortCode: "FRL", label: "French - Luxembourg", },
    { longCode: "fr-mc"   , shortCode: "FRA", label: "French - Monaco", },
    { longCode: "fr-ch"   , shortCode: "FRS", label: "French - Switzerland", },
    { longCode: "de"      , shortCode: "DE" , label: "German" },
    { longCode: "de-at"   , shortCode: "DEA", label: "German - Austria", },
    { longCode: "de-de"   , shortCode: "DEU", label: "German - Germany", },
    { longCode: "de-li"   , shortCode: "DEC", label: "German - Liechtenstein", },
    { longCode: "de-lu"   , shortCode: "DEL", label: "German - Luxembourg", },
    { longCode: "de-ch"   , shortCode: "DES", label: "German - Switzerland", },
    { longCode: "el-gr"   , shortCode: "ELL", label: "Greek - Greece", },
    { longCode: "he-il"   , shortCode: "HEB", label: "Hebrew - Israel", },
    { longCode: "hi-in"   , shortCode: "HIN", label: "Hindi - India", },
    { longCode: "hu-hu"   , shortCode: "HUN", label: "Hungarian - Hungary", },
    { longCode: "is-is"   , shortCode: "ISL", label: "Icelandic - Iceland", },
    { longCode: "id-id"   , shortCode: "IND", label: "Indonesian - Indonesia", },
    { longCode: "it-it"   , shortCode: "ITA", label: "Italian - Italy", },
    { longCode: "it-ch"   , shortCode: "ITS", label: "Italian - Switzerland", },
    { longCode: "ja-jp"   , shortCode: "JPN", label: "Japanese - Japan", },
    { longCode: "kk-kz"   , shortCode: "KKZ", label: "Kazakh - Kazakhstan", },
    { longCode: "ko-kr"   , shortCode: "KOR", label: "Korean - Korea", },
    { longCode: "lv-lv"   , shortCode: "LVI", label: "Latvian - Latvia", },
    { longCode: "lt-lt"   , shortCode: "LTH", label: "Lithuanian - Lithuania", },
    { longCode: "ms-my"   , shortCode: "MSL", label: "Malay - Malaysia", },
    { longCode: "nb-no"   , shortCode: "NOR", label: "Norwegian (Birkemeier) - Norway", },
    { longCode: "nn-no"   , shortCode: "NON", label: "Norwegian (Nynorsk) - Norway", },
    { longCode: "pl-pl"   , shortCode: "PLK", label: "Polish - Poland", },
    { longCode: "pt-br"   , shortCode: "PTB", label: "Portuguese - Brazil", },
    { longCode: "pt-pt"   , shortCode: "PTG", label: "Portuguese - Portugal", },
    { longCode: "ro-ro"   , shortCode: "ROM", label: "Romanian - Romania", },
    { longCode: "ru-ru"   , shortCode: "RUS", label: "Russian - Russia", },
    { longCode: "sa-in"   , shortCode: "SAN", label: "Sanskrit - India", },
    { longCode: "cy"      , shortCode: "CY" , label: "Welsh" },
    { longCode: "cy-sr-sp", shortCode: "SRB", label: "Serbian (Cyrillic) - Serbia", },
    { longCode: "lt-sr-sp", shortCode: "SRL", label: "Serbian (Latin) - Serbia", },
    { longCode: "sk-sk"   , shortCode: "SKY", label: "Slovak - Slovakia", },
    { longCode: "sl-si"   , shortCode: "SLV", label: "Slovenian - Slovenia", },
    { longCode: "es"      , shortCode: "ES" , label: "Spanish" },
    { longCode: "es-ar"   , shortCode: "ESS", label: "Spanish - Argentina", },
    { longCode: "es-bo"   , shortCode: "ESB", label: "Spanish - Bolivia", },
    { longCode: "es-cl"   , shortCode: "ESL", label: "Spanish - Chile", },
    { longCode: "es-co"   , shortCode: "ESO", label: "Spanish - Colombia", },
    { longCode: "es-cr"   , shortCode: "ESC", label: "Spanish - Costa Rica", },
    { longCode: "es-do"   , shortCode: "ESD", label: "Spanish - Dominican Republic", },
    { longCode: "es-ec"   , shortCode: "ESF", label: "Spanish - Ecuador", },
    { longCode: "es-sv"   , shortCode: "ESE", label: "Spanish - El Salvador", },
    { longCode: "es-gt"   , shortCode: "ESG", label: "Spanish - Guatemala", },
    { longCode: "es-hn"   , shortCode: "ESH", label: "Spanish - Honduras", },
    { longCode: "es-mx"   , shortCode: "ESM", label: "Spanish - Mexico", },
    { longCode: "es-ni"   , shortCode: "ESI", label: "Spanish - Nicaragua", },
    { longCode: "es-pa"   , shortCode: "ESA", label: "Spanish - Panama", },
    { longCode: "es-py"   , shortCode: "ESZ", label: "Spanish - Paraguay", },
    { longCode: "es-pe"   , shortCode: "ESR", label: "Spanish - Peru", },
    { longCode: "es-pr"   , shortCode: "ESU", label: "Spanish - Puerto Rico", },
    { longCode: "es-es"   , shortCode: "ESS", label: "Spanish - Spain", },
    { longCode: "es-uy"   , shortCode: "ESY", label: "Spanish - Uruguay", },
    { longCode: "es-ve"   , shortCode: "ESV", label: "Spanish - Venezuela", },
    { longCode: "sv-fi"   , shortCode: "SVF", label: "Swedish - Finland", },
    { longCode: "sv-se"   , shortCode: "SVE", label: "Swedish - Sweden", },
    { longCode: "syr-sy"  , shortCode: "SYR", label: "Syriac - Syria", },
    { longCode: "th-th"   , shortCode: "THA", label: "Thai - Thailand", },
    { longCode: "tr-tr"   , shortCode: "TRK", label: "Turkish - Turkey", },
    { longCode: "uk-ua"   , shortCode: "URK", label: "Ukrainian - Ukraine", },
    { longCode: "ur-pk"   , shortCode: "URD", label: "Urdu - Pakistan", },
    { longCode: "vi-vn"   , shortCode: "VIT", label: "Vietnamese - Vietnam", },
    { longCode: "dv"      , shortCode: "DV" , label: "Divehi" },
    { longCode: "dv-mv"   , shortCode: "DIV", label: "Divehi - Maldives" },
    { longCode: "el"      , shortCode: "EL" , label: "Greek" },
    { longCode: "gl"      , shortCode: "GL" , label: "Galician" },
    { longCode: "gl-es"   , shortCode: "GLC", label: "Galician - Spain" },
    { longCode: "gu"      , shortCode: "GU" , label: "Gujarati" },
    { longCode: "gu-in"   , shortCode: "GUJ", label: "Gujarati - India" },
];

const longCodeToMetadataLanguageObject = new Map(getObjectArrayMapEntries(supportedLanguagesLongCode, l => l.longCode));
const shortCodeToMetadataLanguageObject = new Map(getObjectArrayMapEntries(supportedLanguagesLongCode, l => l.shortCode));

export function longCodeTextToMetadataLanguage(text?: string): LocalLanguage | undefined {
    return text ? longCodeToMetadataLanguageObject.get(text.toLowerCase()) : undefined;
}

export function shortCodeTextToMetadataLanguage(text?: string): LocalLanguage | undefined {
    return text ? shortCodeToMetadataLanguageObject.get(text.toUpperCase()) : undefined;
}
